
library(mongolite)

mongo_stock <- function(coll, host="localhost") {
  m <- mongo(coll, "stock", paste("mongodb://", host, sep=""))
  return(m$find())
}

thedate <- "20170705"
mongo_remote <- "localhost"

toptoday <- mongo_stock(paste("toptoday"), host=mongo_remote)

get_profit_data <- function(year, month) {
  profit <- mongo_stock(paste("profit_data", year, month, sep = "_"), host=mongo_remote)
  return(profit)                        
}

get_topbefore_more <- function(day) {
  x <- mongo_stock(paste("topbefore", thedate, day, "days", sep = "_"), host=mongo_remote)
  x <- x[order(-x$count),]
  return(x)
}

parse_toptopday <- function(fromdata) {
  choosefrom <- toptoday[toptoday$date > fromdata,]
  x <- as.data.frame(table(choosefrom$name))
  x <- x[order(-x$Freq),]
  return(x)
}

#toptoday[order(-as.numeric(toptoday$amount)),]
#toptoday_s <- parse_toptopday("2017-06-26")


